﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Common.Net.Utilities
{
    public static class AttributeHelper
    {
        public static bool HasAttribute<TAttr>(this MemberInfo member)
            where TAttr : Attribute
        {
            return member.GetCustomAttributes(true).Any(a => a.GetType().Name == typeof(TAttr).Name);
            //return Attribute.IsDefined(member, typeof(TAttr));
        }

        public static TAttr GetAttribute<TAttr>(this MemberInfo member)
            where TAttr: Attribute
        {
            return (TAttr)Attribute.GetCustomAttribute(member, typeof(TAttr));
        }
    }
}
